﻿Ext.onReady(function() {

    Ext.QuickTips.init(); // 浮动信息提示
    Ext.BLANK_IMAGE_URL = strPath + 'extjs/resources/images/default/s.gif'; // 替换图片文件地址为本地

    //更改密码窗口
    winUpdatePwd = new Ext.Window({
        title: "更改密码",
        width: 380,
        height: 150,
        layout: 'fit',
        plain: true,
        constrain: true, // windows不超过浏览器
        autoScroll: 'true',
        closeAction: 'hide',
        modal: true,
        deferredRender: false,
        resizable: false,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        contentEl: 'divUpdatePwdWin',
        bodyStyle: 'border-top:0;padding:2 2 2 2;background:#E5E2EE;',
        closeAction: 'hide'
    });

    var myPanel = new Ext.Panel({
        region: 'center',
        id: 'myPanel',
        layout: 'fit',
        margins: '8 1 6 1',
        html: ' <div style="margin:0px; height:100%;"><iframe id="ContentFrame" name="ContentFrame" src="main.htm" width="100%" height="100%" frameborder="0" scrolling="Auto"  ></iframe></div>'
    });

    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [
                new Ext.BoxComponent({ // raw
                    region: 'north',
                    el: 'north',
                    height: 71
                }),
                 {
                     region: 'west',
                     id: 'west-panel',
                     title: '功能菜单',
                     split: false,
                     width: 200,
                     minSize: 175,
                     maxSize: 400,
                     collapsible: true,
                     margins: '8 0 6 6',
                     layout: 'accordion',
                     allowDomMove: false,
                     layoutConfig: {
                         titleCollapse: true,
                         collapseFirst: true,
                         animate: true
                     },
                     collapseMode: 'mini',
                     listeners: {
                         collapse: function() {
                             document.frames('ContentFrame').location.reload();
                         },
                         expand: function() {
                             document.frames('ContentFrame').location.reload();
                         }
                     },
                     items: [
                    {
                        contentEl: 'divDJ',
                        title: '单据管理',
                        handle: AddMenuTree('1000', '监测首页'),
                        border: false,
                        iconCls: 'nav'
                    }, {
                        contentEl: 'divSystemManager',
                        title: '系统设置',
                        handle: AddMenuTree('9000', '系统设置'),
                        border: false,
                        iconCls: 'settings'
                    }
                    ]
                 },
                myPanel
             ]
    });
});

function AddMenuTree(MenuID, MenuName) {
    var Tree = Ext.tree;
    var tree = new Tree.TreePanel({
        el: 'divMenuTree_' + MenuID,
        autoScroll: true,
        animate: true,
        enableDD: true,
        rootVisible: false,
        containerScroll: true,
        border: false,
        loader: new Tree.TreeLoader({
            dataUrl: '/SystemManage/GetUserMenuTree.aspx?MenuID=' + MenuID// 动态载入数据的请求地址
        })
    });
    var root = new Tree.AsyncTreeNode({
        text: MenuName,
        draggable: false,
        id: MenuID,
        expanded: true

    });
    tree.setRootNode(root);
    tree.render();
    root.expand();
}

function GetFrameWidth() {
    return Ext.get("ContentFrame").getWidth();
}

function GetFrameHeight() {
    return Ext.get("ContentFrame").getHeight();
}

function showUpdatePwdWin() {
    document.getElementById("oldpwd").value = "";
    document.getElementById("newpwd").value = "";
    document.getElementById("divUpdatePwdWin").style.display = "block";
    winUpdatePwd.show();
}

function btnUpdatePwd() {
    var strOldPwd = document.getElementById("oldpwd").value;
    var strNewPwd = document.getElementById("newpwd").value;
    if (strOldPwd == '' || strOldPwd == null) {
        Ext.MessageBox.alert("提示", "请输入旧密码！");
        return;
    }
    if (strNewPwd == '' || strNewPwd == null) {
        Ext.MessageBox.alert("提示", "请输入新密码！");
        return;
    }
    else {
        if (strNewPwd.length > 16) {
            Ext.MessageBox.alert("提示", "请输入16位以内密码！");
            return;
        }
    }

    var myMask = new Ext.LoadMask(Ext.getBody(), {
        msg: "正在更新数据..."
    });
    myMask.show();
    var strUrl = strPath + 'GGFW/SystemManage/UserCommand.fwf?Method=UpdatePwd';
    Ext.Ajax.request({
        url: strUrl,
        method: 'POST',
        timeout: 60000, //设定超时时间为60秒
        params: {
            OldPwd: strOldPwd,
            NewPwd: strNewPwd
        },
        failure: function(response, options) {
            ReturnValue = Ext.MessageBox.alert("警告", "网络异常或登录过期，请重新登录！");
            myMask.hide();
        },
        success: function(response, options) {
            myMask.hide();
            var json = response.responseText;
            var obj = parseJsonResult(json);
            if (!obj.Success) {
                showMessage("错误！", "更改密码出错！请查看详细原因。", obj.Message);
            }
            else {
                alert("密码更改成功，请重新登录！");
                window.location.href("Logout.aspx");
            }
        }
    });
}

function btnCloseWin() {
    winUpdatePwd.hide();
}